<template>
  <!-- 翻牌抽奖效果 -->
  <view class="flop_main">
    <swiper
      class="swiper"
      :indicator-dots="indicatorDots"
      :autoplay="autoplay"
      :interval="interval"
      :duration="duration"
      previous-margin="100px"
      next-margin="100px"
      @change="swiperChange"
      :current="current"
    >
      <swiper-item class="swiper_content" v-for="(item,index) in wardList" :key="index">
        <view class="swiper-item" @click="chooseCard(index)" :class="index==current?'active':''">
          <div class="front" :class="item.choose?'active':''">
            <div class="btn_open">点击开奖</div>
          </div>
          <div class="back" :class="item.choose?'active':''">{{item.name}}</div>
        </view>
      </swiper-item>
    </swiper>
  </view>
</template>
<script>
export default {
  data() {
    return {
      background: ["color1", "color2", "color3"],
      indicatorDots: false,
      autoplay: false,
      interval: 2000,
      duration: 500,
      current: 1,
      wardList: [
        { name: "一等奖", choose: false },
        { name: "二等奖", choose: false },
        { name: "三等奖", choose: false },
      ],
    };
  },
  methods: {
    chooseCard(e) {
      this.wardList[e].choose = true;
    },
    swiperChange(e) {
      this.current = e.detail.current;
      console.log(e);
    },
  },
};
</script>
<style lang="scss" scoped>
.swiper_content {
  display: flex;
  justify-content: center;
  align-items: center;
}
.flop_main {
  width: 750rpx;
  height: 500rpx;
  margin: 0 auto;
}
.swiper {
  height: 500rpx;
}
.swiper-item.active {
  height: 100%;
}
.swiper-item {
  width: 90%;
  height: 90%;
  margin: 0 auto;
  position: relative;
}
uni-swiper-item {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 90%;
  height: 90%;
  margin: 0 20rpx;
}
.front,
.back {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition: all 2s;
  -webkit-transition: all 2s;
  background: coral;
}
.btn_open {
  width: 200rpx;
  font-size: 30rpx;
  color: white;
  background-color: #d70c19;
  border-radius: 20rpx;
  height: 60rpx;
  line-height: 60rpx;
  margin: 20rpx;
  text-align: center;
}
.back {
  transform: rotateY(180deg);
  opacity: 0;
}

.back.active {
  animation: fan 1s forwards;
  -webkit-animation: fan 1s forwards;
}
.front.active {
  animation: zheng 1s forwards;
  -webkit-animation: zheng 1s forwards;
}
@keyframes zheng {
  from {
    transform: rotateY(0);
    z-index: 12;
    opacity: 1;
  }

  to {
    transform: rotateY(180deg);
    z-index: 0;
    opacity: 0;
  }
}

@keyframes fan {
  from {
    transform: rotateY(180);
    z-index: 0;
    opacity: 0;
  }

  to {
    transform: rotateY(360deg);
    z-index: 12;
    opacity: 1;
  }
}
</style>